class FetionsController < ApplicationController
   # admin
  before_filter :authorize_for_admin, :only => [:verify_in_users_index, :check_verify_in_users_index]

  def authorize
  end
    
  def create
  end
  
  def send_check_code_sm
    send_sm_and_render do
      session[:fetion_check_code] ||= ActiveSupport::SecureRandom.hex(2)
      current_user.send_check_code_sm! session[:fetion_check_code], 
        :mobile => params[:mobile], 
        :password => params[:fetion_password],
        :verifyImgId  => params[:fetion_verify_image_id],
        :verifyCode => params[:fetion_verify_code]
    end
  end
  
  def verify
    @verify_image = FetionVerifyImage.find(params[:mobile])
  end

  def new_verify_in_users_index
    @user = User.find(params[:id])
    @verify_image = FetionVerifyImage.find(@user.mobile)
  end

  def check_verify_in_users_index
    @user = User.find(params[:id])
    @friends = FetionFriend.find(:all, :params => {
      :mobile => @user.mobile, 
      :password => @user.fetion_password,
      :verifyImgId  => params[:verify_image_id],
      :verifyCode => params[:verify_code]
    })
    @friends.first.state == 'SUCCESS' ? render(:status => 200, :text => 'SUCCESS') : render(:status => 500, :text => @friends.first.state)
  end
end
